import useAppStore from '../../manager/app'

const sharePrimise = Symbol('sharePrimise')
function delayTime(data, time) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(data)
    }, time)
  })
}
export default {
  data() {
    return {
      [sharePrimise]: null
    }
  },
  methods: {
    setPageShareData(api) {
      this[sharePrimise] = api
    },
    async getPageShareData() {
      const appStore = useAppStore()
      const initConfig = appStore.wxShare

      const { title = initConfig.title, path = initConfig.path, imageUrl = initConfig.imageUrl } = await this[sharePrimise]
      return {
        title,
        path,
        imageUrl
      }
    }
  },
  // #ifdef MP-WEIXIN
  async onShareAppMessage(res) {
    // // 设置默认的转发参数
    // if (res.from === 'button') {
    //   return
    // }
    await delayTime(true, 50)
    return this.getPageShareData()
  },
  async onShareTimeline(res) {
    await delayTime(true, 50)
    return this.getPageShareData()
  }
  // #endif
}
